package com.mca.framework.completableFuture;

import java.util.concurrent.*;

/**
 * @Author: zhoupeng
 * @createTime: 2025年07月11日 10:00:26
 * @version: 1.0
 * @Description:
 * @copyright:
 */
public class SupplyAsyncDemo {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(100);
        CompletableFuture<Integer> future=CompletableFuture.supplyAsync(()->{
            //子任务
            try {
                TimeUnit.SECONDS.sleep(3);
                System.out.println(Thread.currentThread().getName());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return 123;
        },executorService);
        //主任务
        System.out.println("main end ");
        //获取子任务结果
        try {
            Integer value = future.get();
            System.out.println(value);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

        executorService.shutdown();
    }
}
